package com.zhx.threadcoreknowledge.uncaughtexception;

/**
 * @author ：zhanghaixuan
 * @date ：Created in 2019-10-04 11:00
 * 用途         ：
 * 1.不加try/catch的时候抛出四个异常,都带线程名字
 * 2. 加了 try/catch,期望捕获到第一个线程的异常,
 * 线程234不应该运行  ,希望看到打印出 Caught Exception
 * 3, 实际运行:没有看到caught exception 线程234 依然运行并抛出异常
 *
 * 说明线程的异常不能用传统方法捕获
 */
public class CantCatrchDirectly implements Runnable{

    @Override
    public void run() {
        throw new RuntimeException("报错了");
    }

    public static void main(String[] args) throws InterruptedException {
        try {
        new Thread(new CantCatrchDirectly(),"my-thread-1").start();
        Thread.sleep(300);
        new Thread(new CantCatrchDirectly(),"my-thread-2").start();
        Thread.sleep(300);
        new Thread(new CantCatrchDirectly(),"my-thread-3").start();
        Thread.sleep(300);
        new Thread(new CantCatrchDirectly(),"my-thread-4").start();
        } catch (RuntimeException e){
            System.out.println("caught exception");
        }
    }
}
